package cz.none.bezbarier.web.util;

import java.util.logging.Logger;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;

public class GaeAppender extends AppenderSkeleton {

	private Logger logger = Logger.getLogger(GaeAppender.class.getName());

	@Override
	public void close() {
		logger = null;

	}

	@Override
	public boolean requiresLayout() {
		return true;
	}

	@Override
	protected void append(LoggingEvent event) {
		Level level = event.getLevel();

		if (level == Level.FATAL) {
			logger.severe(this.layout.format(event));
		} else if (level == Level.ERROR) {
			logger.severe(this.layout.format(event));
		} else if (level == Level.WARN) {
			logger.warning(this.layout.format(event));
		} else if (level == Level.INFO) {
			logger.info(this.layout.format(event));
		} else if (level == Level.DEBUG) {
			logger.fine(this.layout.format(event));
		} else {
			logger.fine(this.layout.format(event));
		}

	}

}
